package co.edu.poli.ficb.agl.automatable.util;

import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

import co.edu.poli.ficb.agl.automatable.modelo.automatas.Estado;

public class SetUtils {
	
	public static <T extends Comparable<T>> Set<T> difference(Set<T> a, Set<T> b) {
		TreeSet<T> s = new TreeSet<T>();
		for (T t : a) if (!b.contains(t)) s.add(t);
		return s;
	}
	
	public static <T extends Comparable<T>> Set<T> union(Set<T> a, Set<T> b) {
		TreeSet<T> s = new TreeSet<T>();
		for (T t : a) s.add(t);
		for (T t : b) s.add(t);
		return s;
	}
	
	public static <T> String toString(Set<T> s) {
		if (s == null)
			return "null";
		return Arrays.toString(s.toArray());
	}
	
	public static void main(String[] args) {
		Set<Character> a = new TreeSet<Character>(Arrays.asList(new Character[]{'a','b','c','d'}));
		Set<Character> b = new TreeSet<Character>(Arrays.asList(new Character[]{'a','b','e'}));
		Set<Character> c = SetUtils.difference(a, b);
		Set<Character> d = SetUtils.difference(b, a);
		System.out.println(c.size());
		System.out.println(SetUtils.toString(c));
		System.out.println(SetUtils.toString(d));
	}
	
	public static Set<Estado> clone(Set<Estado> a) {
		Set<Estado> set = new TreeSet<Estado>();
		for (Estado e : a) {
			set.add(e.clone());
		}
		return set;
	}

}
